方式一
测试环境
Ubuntu 18.04
Nginx
准备
- 开放云服务器 443 端口
- 开放系统 443 端口
Note:https 成功后,记得把网站所有连接换成 https
1. 介绍
Let’ s Encrypt已有免费的证书可用,以后的网站估计都要上https的吧,所以把我的网站上的证书换了一下,这节主要是参考使用 acme.sh 给 Nginx 安装 Let’ s Encrypt 提供的免费 SSL 证书这篇文章,并结合自己的情况,把我的经验记录下来。
2. 安装
我们使用acme.sh来申请和管理证书,它很简单用,还能够利用crontab自动更新证书,而且是默认就有的功能。
首先安装:
1 2 3
| 1、cd 2、wget -O - https://get.acme.sh | sh 3、cd .acme.sh
|
安装完之后,可以退出登录,再重新登录,或者执行一下『source ~/.bashrc』。
之后就可以使用 acme.sh 命令了。
3. 申请证书
首先申请和下载证书:
1 2
| # -w 后面写上你自己的网站根目录 -d 自己的网站域名 ./acme.sh --issue -d www.nicefutureworld.com -w /home/wwwroot/www.nicefutureworld.com/current/public
|
申请成功后,证书会被保存在 .acme.sh 目录里面的 www.nicefutureworld.com 目录里面:
![fc61f2da01de2d5389a4e5e0f6e9119.png](https://www.nicefutureworld.com/storage/article/2019/07/25/5gbruO0pn4Ln71CQSGj3q9UWbs7lEXRNv5mMg4Vh.png)
接下来我们要把证书安装到你的应用中:
1 2 3 4 5
| # ssl 文件夹不存在则先创建,需要有写的权限 ./acme.sh --installcert -d boat.rails365.net \ --keypath /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key \ --fullchainpath /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key.pem \ --reloadcmd "sudo lnmp reload"
|
接下来,还需要再生成一个文件,很多ssl的配置都需要它:
1
| openssl dhparam -out /home/wwwroot/www.nicefutureworld.com/ssl/dhparam.pem 2048
|
4. nginx配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| upstream boat_manager { server unix:///home/wwwroot/www.nicefutureworld.com/shared/tmp/sockets/puma.sock fail_timeout=0; }
server { listen 443 ssl; server_name www.nicefutureworld.com; ssl_certificate /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key.pem; ssl_certificate_key /home/wwwroot/www.nicefutureworld.com/ssl/www.nicefutureworld.com.key; # ssl_dhparam ssl_dhparam /home/wwwroot/www.nicefutureworld.com/ssl/dhparam.pem; root /home/wwwroot/www.nicefutureworld.com/current/public keepalive_timeout 70; # 其它配置保持不变 }
server { listen 80; server_name www.nicefutureworld.com; return 301 https://www.nicefutureworld.com$request_uri; }
|
顶层的http指令那里,也需要加上这两行:
1 2 3 4
| http { ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; }
|
原文地址:https://www.qiuzhi99.com/articles/shi-yong-acme-sh-an-zhuang-let-s-encrypt-ti-gong-mian-fei-ssl-zheng-shu
方式二
准备:
先停止 Nginx
使用:https://certbot.eff.org
选择自己的环境与系统:如 Nginx Ubuntu18.04
![ab86c122dfd676d9b6756551565213f.png](https://www.nicefutureworld.com/storage/article/2019/07/25/C1kZHFtlEJ2AVSpUu8jZQlqZAjxNBJl2DZyz7KNu.png)
接下来就是按文档步骤操作:操作完以后把 Nginx 配置跟上一样
![e4bad6e0104596364783869c266cebb.png](https://www.nicefutureworld.com/storage/article/2019/07/25/TT9wnAovZTQ0zMhUMxQQCFlnWUjM3ksb36eC7giu.png)
![c4f9fe7af9bda18f4fa28453ee554fa.png](https://www.nicefutureworld.com/storage/article/2019/07/25/5Bc64yUdqCG0XyzFTENee7x9sTzsSpshOEhC5xAB.png)
![e835c2150102fdeefeaf207bf03bb5c.png](https://www.nicefutureworld.com/storage/article/2019/07/25/qNv7XHvzONrAWSat9yA7JUvG8yoHhLUvCVWFFk4V.png)